const app = getApp()
let qCloud = require("../../index.js");

Page({
    /** 页面的初始数据 */
    data: {
        imgPath: qCloud.config.STATIC_IMAGE_PATH,
        wagesList: [],
        enterpriseStaffTotal: 0, // 员工总数
        enterpriseMonthWagesTotal: 0, // 本月工资总额
    },

    bindGoTo: function (e) {
        wx.navigateTo({
            url: e.currentTarget.dataset.url
        })
    },

    /** 生命周期函数--监听页面加载 */
    onLoad: function (options) {
        let self = this;

        // 查询企业工资列表
        self.queryEnterpriseWagesList();
    },

    /** 查询企业工资列表 */
    queryEnterpriseWagesList() {
        let self = this;
        let params = {};

        app.fetchApis(self, qCloud.api.wages_queryEnterpriseWagesList, params, "POST", function (e) {
            let result = e.data;
            if (result.code == 200) {
                let data = result.data;
                for (let index = 0; index < data.wagesList.length; index++) {
                    data.wagesList[index].avatar = "avatar.jpg";
                }
                self.setData({
                    wagesList: data.wagesList,
                    enterpriseStaffTotal: data.enterpriseStaffTotal,
                    enterpriseMonthWagesTotal: data.enterpriseMonthWagesTotal,
                });

                // 获取当前公司用户信息
                self.getMyOrganUserList();
            }
        });
    },


    // 获取当前公司用户信息
    getMyOrganUserList() {
        let self = this;

        let params = {};

        app.fetchApis(self, qCloud.api.getMyOrganUserList, params, "GET", function (e) {
            let result = e.data;

            if (result.code == 200) {
                let data = result.data;
            }
        });
    },


    /** 页面相关事件处理函数--监听用户下拉动作 */
    onPullDownRefresh: function () {
        let self = this;
        // 查询企业工资列表
        self.queryEnterpriseWagesList();
    },


});
